﻿using WatchDog;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WatchDog.WinForm
{
    public partial class SettingForm : Form
    {
        private int _id = 0;
        public SettingForm()
        {
            InitializeComponent();
        }
        public SettingForm(int id):this()
        {
            _id = id;
        }

        private void save_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(this.textBox1.Text))
            {
                MessageBox.Show("请选择要监控的程序路径", "提示", MessageBoxButtons.OK);
                return;
            }

            var service = new FileService();
            service.Add(new WatchDog.FileInfo
            {
                Remark = this.richTextBox1.Text,
                FilePath = this.textBox1.Text,
                DisplayName = Path.GetFileName(this.textBox1.Text),
                FileName = Path.GetFileName(this.textBox1.Text),
                AutoStart = true,   
            });
            this.Close();
        }

        private void select_Click(object sender, EventArgs e)
        {
            var s = new OpenFileDialog();
            s.Filter = "(*.exe)|*.exe";
            s.Multiselect = false;
            if (s.ShowDialog() == DialogResult.OK)
            {
                this.textBox1.Text = s.FileName;// strNames[0];   
            }
        }
    }
}
